feat(ai-security-guard): add Redis-based message deduplication for content moderation#3650
Open
JianweiWang wants to merge 3 commits intohigress-group:mainfrom
Open
feat(ai-security-guard): add Redis-based message deduplication for content moderation#3650JianweiWang wants to merge 3 commits intohigress-group:mainfrom
JianweiWang wants to merge 3 commits intohigress-group:mainfrom
Conversation
1. 去重粒度: 按消息级别去重,通过 SHA256(策略指纹 + consumer + role + content + 图片指纹) 生成唯一键 2. 缓存安全: 策略指纹包含所有影响检测结果的维度,策略变更时自动失效缓存 3. 降级策略: Redis 不可用时自动关闭去重,Lua 脚本失败降级为逐条写入
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
为
ai-security-guard插件新增基于 Redis 的消息去重机制,避免对相同内容进行重复的安全检测,提升性能并降低对后端安全检测服务的调用量。核心设计
SHA256(策略指纹 + consumer + role + content + 图片指纹)生成唯一键变更范围
config/config.go- 新增 Redis 去重相关配置lvwang/common/check_helper.go- 新增通用检测辅助工具(含去重逻辑)lvwang/multi_modal_guard/text/openai.go- 多模态检测集成去重lvwang/text_moderation_plus/text/openai.go- 文本审核集成去重utils/utils.go- 新增 SHA256 哈希等工具函数测试覆盖
新增和更新了多个测试文件(+2000 行测试代码):
config/config_test.golvwang/common/check_helper_test.golvwang/multi_modal_guard/text/openai_test.gomain_test.goutils/utils_test.go